package
{
	import flash.display.Sprite;
	import flash.utils.getTimer;

	public class Test1 extends Sprite
	{
		private const time_int:int       = 100000000;
		private const time_uint:uint     = 100000000;
		private const time_Number:Number = 100000000;
		private var old:int;
		
		public function Test1()
		{
			switch(8)
			{
				case 1:
					test_int();
					break;
				case 2:
					test_uint();
					break;
				case 3:
					test_Number();
					break;
				case 4:
					test_for();
					break;
				case 5:
					test_while();
					break;
				case 6:
					test_plusplus();
					break;
				case 7:
					test_plusone();
					break;
				case 8:
					test_varplusone();
					break;
			}
		}
		
		/**
		 * 1亿次计算
		 * int)    1014 1008 988
		 * uint)   985  1006 994
		 * Number) 1745 1744 1749
		 * Speed: uint>int>Number
		 * for)    9804
		 * while)  9636
		 * Speed: while>for
		 * var++)     9634
		 * var+=1)    9641
		 * var=var+1) 8995
		 * Speed: var=var+1>var++>var+=1
		 */		
		private function test_int():void
		{
			old = getTimer();
			for (var i:int = 0; i < time_int; i++) 
			{
				
			}
			trace(getTimer() - old);
		}
		
		private function test_uint():void
		{
			old = getTimer();
			for (var i:uint = 0; i < time_uint; i++) 
			{
				
			}
			trace(getTimer() - old);
		}
		
		private function test_Number():void
		{
			old = getTimer();
			for (var i:Number = 0; i < time_Number; i++) 
			{
				
			}
			trace(getTimer() - old);
		}
		
		private function test_for():void
		{
			old = getTimer();
			for (var i:int = 0; i <= time_int; i++) 
			{
				if(i==time_int)
					trace(getTimer() - old);
			}
		}
		
		private function test_while():void
		{
			var i:int = 0;
			old = getTimer();
			while(i<=time_int)
			{
				i++;
			}
			trace(getTimer() - old);
		}
		
		private function test_plusplus():void
		{
			old = getTimer();
			var k:uint = 0;
			for (var i:uint = 0; i < time_uint; i++) 
			{
				k++;
			}
			trace(getTimer() - old);
		}
		
		private function test_plusone():void
		{
			old = getTimer();
			var k:uint = 0;
			for (var i:uint = 0; i < time_uint; i++) 
			{
				k += 1;
			}
			trace(getTimer() - old);
		}
		
		private function test_varplusone():void
		{
			old = getTimer();
			var k:uint = 0;
			for (var i:uint = 0; i < time_uint; i++) 
			{
				k = k + 1;
			}
			trace(getTimer() - old);
		}
	}
}